#!/usr/bin/env python
# -*- coding: utf-8 -*-


from PyQt5 import  QtWidgets,QtCore,QtCore
import os,subprocess
from launch_app import launchMaya2016,launchMaya2017,launchMaya2018

file_path = str(os.path.split(os.path.realpath(__file__))[0])


class MyLabel(QtWidgets.QLabel):
    launch_maya_signal = QtCore.pyqtSignal(str)
    # change_color_signal = QtCore.pyqtSignal(str)
    def __init__(self,parent=None):
        super(MyLabel,self).__init__(parent)

    def mouseDoubleClickEvent(self,py_file):
        self.launch_maya_signal.emit("launch_maya")
        self.launch_maya_signal.connect(lambda :launch_app(py_file))

    # def mousePressEvent(self, QToolButton):
    #     self.change_color_signal.emit("change_blue")
    #     self.change_color_signal.connect(lambda :set_button_blue(QToolButton))


def launch_app(py_file):

    try:
        py_file.main()
    except:
        pass


# def set_button_blue(QToolButton):
#
#     QToolButton.setStyleSheet("selection-color: rgb(100, 200, 200);")


def add_launch_buttons(QGroupBox):
    mayabutton2016 = MyLabel()
    mayabutton2017 = MyLabel()
    mayabutton2018 = MyLabel()

    mayabutton2016.setStyleSheet("image: url(:/icons/maya2016.png);")
    # mayabutton2016.resize(100,300)
                                 # "height: 500px;width: 652px;border: none;")
                                 # "background-color: rgb(200, 200, 200);")
    mayabutton2017.setStyleSheet("image: url(:/icons/maya2017.png);")
                                 # "height: 500px;width: 652px;border: none;")
                                 # "background-color: rgb(200, 200, 200);")
    mayabutton2018.setStyleSheet("image: url(:/icons/maya2018.png);")
                                 # "height: 500px;width: 652px;border: none;")
                                 # "background-color: rgb(200, 200, 200);")
    layout = QtWidgets.QHBoxLayout()
    layout.addWidget(mayabutton2016)
    layout.addWidget(mayabutton2017)
    layout.addWidget(mayabutton2018)

    mayabutton2016.mouseDoubleClickEvent(launchMaya2016)
    mayabutton2017.mouseDoubleClickEvent(launchMaya2017)
    mayabutton2018.mouseDoubleClickEvent(launchMaya2018)
    # mayabutton2016.mousePressEvent(mayabutton2016)
    # mayabutton2017.mousePressEvent(mayabutton2017)
    # mayabutton2018.mousePressEvent(mayabutton2018)

    QGroupBox.setLayout(layout)

    return True
